//
//  MainViewController.m
//  ZooNgonDoiOS
//
//  Created by Trung sound on 6/5/12.
//  Copyright (c) 2012 Personal. All rights reserved.
//

#import "MainViewController.h"
#import "HomeViewController.h"
#import "TopLikeViewController.h"
#import "TopNewController.h"
#import "CreateFoodViewController.h"
#import "CreateSpotViewController.h"
#import "IndividualViewController.h"
#import "CommentViewController.h"

@implementation MainViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        _tabBarController = [[UITabBarController alloc]init];
        [_tabBarController.tabBar setHidden:NO];

        
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    HomeViewController *homeViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
    NSLog(@"%@",homeViewController.view.frame.size.height);
    CreateFoodViewController *createFoodViewController = [[CreateFoodViewController alloc]init];
    IndividualViewController *individualViewController = [[IndividualViewController alloc]init];
    CommentViewController *commentViewController = [[CommentViewController alloc]initWithObject:@"a"];
    
    
    homeViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:nil tag:1];
    [homeViewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:IMG_BTN_HOME_SELECTED] withFinishedUnselectedImage:[UIImage imageNamed:IMG_BTN_HOME_NORMAL]];
    
    createFoodViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:nil tag:2];
    [createFoodViewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:IMG_BTN_TALK_SELECTED] withFinishedUnselectedImage:[UIImage imageNamed:IMG_BTN_TALK_NORMAL]];
    
    individualViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:nil tag:3];
    [individualViewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:IMG_BTN_ME_SELECTED] withFinishedUnselectedImage:[UIImage imageNamed:IMG_BTN_ME_NORMAL]];
    
    commentViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:nil tag:4];
    [commentViewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:IMG_BTN_CHECKIN_SELECTED] withFinishedUnselectedImage:[UIImage imageNamed:IMG_BTN_CHECKIN_NORMAL]];

    _tabBarController.viewControllers = [NSArray arrayWithObjects:homeViewController, createFoodViewController, individualViewController, commentViewController,nil];

    _tabBarController.tabBar.frame = CGRectMake(0, 0, self.view.bounds.size.width, 48);
//    [_tabBarController.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:TABBAR_BACKGROUND]]];

    [_tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:@"img_nav_background.png"]];
    
    [self.view addSubview:_tabBarController.view];
    
    [self fixPositionTabBar];


//    [self.tabBarController.tabBar setHidden:YES];
//    self.view.backgroundColor = [UIColor whiteColor];
}

- (void)fixPositionTabBar {
    for(UIView *view in _tabBarController.view.subviews)
        {
        CGRect _rect = view.frame;
        
        if([view isKindOfClass:[UITabBar class]])
            {
            _rect.origin.y = 0;
            [view setFrame:_rect];
            
            } else {
                _rect.size.height = 480;
                [view setFrame:_rect];
            }  
        }
}

- (void) pushToDetailController:(ZooSpotBean *)pSpot {
    DetailViewController *detailViewController = [[DetailViewController alloc]initWithSpot:pSpot];
    detailViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    detailViewController.spotDetailDelegate = self;
    [self presentModalViewController:detailViewController animated:YES];
        //    [self.navigationController pushViewController:detailViewController animated:YES];
    [detailViewController release];
}

- (void)viewDidUnload
{

    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)dealloc {
    [super dealloc];
}
@end
